package com.stars.empoly.activity

import android.os.Bundle
import android.util.Log
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.adapter.BillToAdapter
import com.stars.empoly.base.MBRActivity
import com.stars.empoly.databinding.ActivityBillBinding
import com.stars.empoly.inte.ChoiceData
import com.stars.empoly.inte.ChoiceListData
import com.stars.empoly.utils.PopuChoseTime
import com.stars.empoly.utils.PopuChoseTypeUtils
import com.stars.empoly.vmodel.BillVModel
import java.text.SimpleDateFormat
import java.util.*

/**
 *on 2022/9/23
 */
class BillActivity: MBRActivity<BillVModel, BillToAdapter, ActivityBillBinding>()  {

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        var s = SimpleDateFormat("yyyy-MM").format(Date())
        var simpleDateFormat = SimpleDateFormat("yyyy-MM")
        var date = simpleDateFormat.parse(s)
        var ts = date.time
        vm.time = ts.toString()
        binding.tvTime.text = SimpleDateFormat("yyyy-MM").format(Date())
        vm.getCount()
    }

    override fun listeners() {
        super.listeners()

        binding.llAll.onClick {
            PopuChoseTypeUtils.show(context(), binding.llAll, object : ChoiceListData {
                override fun onRestuse(id: String?, name: String?) {

                    vm.type = id
                    binding.tvAll.text = name
                    vm.getCount()
                    onRefresh()

                }


            })
        }

        binding.llTime.onClick {
            //时间

            PopuChoseTime.show(context(), binding.llTime, object : ChoiceListData {
                override fun onRestuse(time: String?, type: String?) {
                    vm.timeType = type
                    //时间
                    binding.tvTime.text = time

                    Log.e("-time-", "type=: " + type)
                    Log.e("-time-", "time=: " + time)


                    if (type == "0") {
                        var simpleDateFormat = SimpleDateFormat("yyyy-MM")

                        var date = simpleDateFormat.parse(time)
                        var ts = date.time
                        vm.time = ts.toString()

                    } else {
                        var simpleDateFormat = SimpleDateFormat("yyyy-MM-dd")

                        var date = simpleDateFormat.parse(time)
                        var ts = date.time
                        vm.time = ts.toString()
                    }
                    vm.getCount()
                    onRefresh()


                }

            })

        }
    }
    override fun vmClass(): Class<BillVModel> {
        return BillVModel::class.java
    }
    override fun binding(): ActivityBillBinding {
        return ActivityBillBinding.inflate(layoutInflater)
    }

    override fun initAdapter(): BillToAdapter {
        return BillToAdapter(vm)
    }

    override fun title(): String? {
        return "明细"
    }
    override fun onRefresh() {
        super.onRefresh()
        vm.getCount()
    }
}
